<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
		<title>登录</title>
		<link rel="stylesheet" href="../../libs/css/login.css" />
		<link rel="stylesheet" href="../../css/index.css" />
		<script type="text/javascript" src="../../libs/js/vue.min.js"></script>
		<script type="text/javascript" src="../../libs/js/vant.min.js"></script>
		<script type="text/javascript" src="../../libs/js/ajax.js" ></script>
		<script type="text/javascript" src="../../libs/js/return.js" ></script>
		<script type="text/javascript" src="../../libs/js/vue-toasted.min.js" ></script>
		<script src="html5plus://ready"></script>
		<style type="text/css">
			.S_login {
				margin-top: 20px;
				font-size: 16px;
			}
			
			a {
				color: #000;
			}
		</style>
		<script type="text/javascript">
			document.addEventListener('plusready', function() {
				//console.log("所有plus api都应该在此事件发生后调用，否则会出现plus is undefined。 "
			});
		</script>
	</head>

	<body>
		<div id="applog">
			<div id="">
				<van-nav-bar right-text="更多" left-arrow @click-left="onClickLeft">
			</div>
			<div align="center">
				<img style="margin-top: 20px;" src="../../libs/img/tubiao.jpg" width="50%">
			</div>
			<van-cell-group>
				<van-field class="S_login" maxlength="11" v-model="phone" label="手机号码" left-icon="phone" placeholder="请输入手机号"></van-field>
				<van-field class="S_login" v-model="pwd" type="password" left-icon="wap-home" label="登录密码" placeholder="请输入密码"></van-field>
				<van-row class="S_login">
					<van-col offset="18" span="6">
						<a href="#">忘记密码？</a>
					</van-col>
				</van-row>
				<van-row>
					<van-col span="20" offset="2">
						<van-button class="S_login" size="large" type="danger" @click="loginClick">立即登录</van-button>
					</van-col>
				</van-row>
				<div class="S_login" align="center">还没有注册？
					<a href="zhuce.html" style="color:#FE2E2E">立即注册</a>
				</div>
			</van-cell-group>
		</div>
		<script>
			var app = new Vue({
				el: "#applog",
				data: {
					phone: "",
					pwd: "",
				},
				methods: {
					onClickLeft: function() {
						var ws = plus.webview.currentWebview();
						plus.webview.close(ws);
					},
					loginClick: function() {
						var _this = this;
						ajax({
							dataType: "jsonp",
							url: "http://dsapi.ysd3g.com/api/login",
							data: {
								account: _this.phone,
								password: _this.pwd
							},
							success: function(res) {
								if(res.Error == false) {
									//alert("恭喜登录成功!");
									app.$toast("恭喜登录成功!");
									var personal = plus.webview.getWebviewById("Personalcenter"); //若是登陆成功跳转首页
									personal.reload("Personalcenter");
									var User = JSON.stringify(res); //把JSON格式的用户信息转换成字符串存到变量里
									localStorage.setItem("user", User);
									plus.webview.close("login");
									plus.storage.setItem("key", res.key) //key是登陆后返回的一个值。 其实就是Token.在登陆后，通常会吧这个key存到plus.storage里面.
								} else {
									app.$toast("请检查账号密码是否错误！");
								}
							}
						})
					},
				},
			})
		</script>
	</body>

</html>